<html>
<head><meta charset="utf-8"><title>calling methods on generic const fn rfc#2632 · t-lang · Zulip Chat Archive</title></head>
<h2>Stream: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/index.html">t-lang</a></h2>
<h3>Topic: <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/calling.20methods.20on.20generic.20const.20fn.20rfc.232632.html">calling methods on generic const fn rfc#2632</a></h3>

<hr>

<base href="https://rust-lang.zulipchat.com">

<head><link href="https://rust-lang.github.io/zulip_archive/style.css" rel="stylesheet"></head>

<a name="208860068"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/calling%20methods%20on%20generic%20const%20fn%20rfc%232632/near/208860068" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/calling.20methods.20on.20generic.20const.20fn.20rfc.232632.html#208860068">(Sep 02 2020 at 17:35)</a>:</h4>
<p>Hey <span class="user-mention" data-user-id="124288">@oli</span> and <span class="user-mention" data-user-id="256759">@boats</span> and maybe others -- in today's backlog bonanza we thought it would make sense to schedule a design meeting to discuss the design of <a href="https://github.com/rust-lang/rfcs/pull/2632">https://github.com/rust-lang/rfcs/pull/2632</a> in detail and in particular to look at <span class="user-mention" data-user-id="256759">@boats</span>'s concerns. Maybe in the next few weeks?</p>



<a name="208945530"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/calling%20methods%20on%20generic%20const%20fn%20rfc%232632/near/208945530" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/calling.20methods.20on.20generic.20const.20fn.20rfc.232632.html#208945530">(Sep 03 2020 at 10:11)</a>:</h4>
<p>I'd be interested in joining that meeting. My concerns are mainly around <code>?const</code> and making sure we can properly handle function pointers (and trait objects) in a consistent way in the future (also see <a href="https://github.com/rust-lang/const-eval/issues/56">https://github.com/rust-lang/const-eval/issues/56</a>)</p>



<a name="209128604"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/calling%20methods%20on%20generic%20const%20fn%20rfc%232632/near/209128604" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/calling.20methods.20on.20generic.20const.20fn.20rfc.232632.html#209128604">(Sep 04 2020 at 18:50)</a>:</h4>
<p>We should file a design meeting proposal</p>



<a name="209128614"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/calling%20methods%20on%20generic%20const%20fn%20rfc%232632/near/209128614" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/calling.20methods.20on.20generic.20const.20fn.20rfc.232632.html#209128614">(Sep 04 2020 at 18:50)</a>:</h4>
<p>ideally someone would summarize the agenda a bit</p>



<a name="209128627"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/calling%20methods%20on%20generic%20const%20fn%20rfc%232632/near/209128627" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> nikomatsakis <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/calling.20methods.20on.20generic.20const.20fn.20rfc.232632.html#209128627">(Sep 04 2020 at 18:50)</a>:</h4>
<p>(hint, hint)</p>



<a name="209275266"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/calling%20methods%20on%20generic%20const%20fn%20rfc%232632/near/209275266" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/calling.20methods.20on.20generic.20const.20fn.20rfc.232632.html#209275266">(Sep 07 2020 at 09:31)</a>:</h4>
<p>Both Ralf's and boat's concerns are around <code>?const</code> are actually very related. Quick reminder: <code>T: ?const Trait</code> on a bound marks the bound as unusable (can't call <code>T::function</code>) within the function (except for static uses via <code>T::ASSOC_CONST</code> or <code>T::ASSOC_TY</code>). This is "necessary", because by default all <code>T: Trait</code> bounds on <code>const fn</code> require that there's an <code>impl const Trait</code> for <code>T</code>.</p>
<p>The question raised by boats is whether we really need these bounds (or whether we need them <em>now</em>). They are not strictly necessary for most cases. If you have a bound you don't need, you can just remove it. Though this is not possible in case there are bounds on the struct/enum. Bounds on the type definition are necessary if the <code>Drop</code> impl requires said bounds. This is the case for the internals of e.g. <a href="https://github.com/rust-lang/rust/blob/ffd59bf9c62125813abae8ca52f0ac3a67459e8f/library/alloc/src/raw_vec.rs#L49"><code>RawVec</code></a>.</p>
<p>Ralf's question is how function pointers and trait objects work. So basically whether <code>&amp;dyn Trait</code> types automatically require that the runtime value given must implement <code>const Trait</code>. This is not a requirement in <code>const</code> items, so there would be a discrepancy between <code>const fn</code> and <code>const</code> items, which is not great at all. The same goes for function pointers.</p>
<p>The alternative is to explicitly require users to write <code>T: const Trait</code> and <code>x: &amp;dyn const Trait</code> and <code>f: const fn()</code>, which works, but conflicts with the hypothetical future proposal of <code>T: const Trait</code> bounds on const functions, that allow you to use this <code>T</code> in array lengths, even if the function itself is used at runtime and thus does not actually force the <code>T</code> to have a <code>const Trait</code> impl (except for adding <code>const</code> everywhere being noisy, this is the only concern afaik). I believe there's a workaround, as you can always specify a const generic parameter instead and pass up the requirement to the caller (or use an associated const).</p>



<a name="209275353"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/calling%20methods%20on%20generic%20const%20fn%20rfc%232632/near/209275353" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> oli <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/calling.20methods.20on.20generic.20const.20fn.20rfc.232632.html#209275353">(Sep 07 2020 at 09:32)</a>:</h4>
<p>TLDR: the consistent thing to do would be to add <code>const</code> everywhere and not have a <code>?const</code> concept at all</p>



<a name="209276029"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/calling%20methods%20on%20generic%20const%20fn%20rfc%232632/near/209276029" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/calling.20methods.20on.20generic.20const.20fn.20rfc.232632.html#209276029">(Sep 07 2020 at 09:39)</a>:</h4>
<p>I think a <code>?const</code> concept is still required for expressivity... unless the <code>const</code> you are proposing actually is <code>?const</code></p>



<a name="209276104"></a>
<h4><a href="https://rust-lang.zulipchat.com#narrow/stream/213817-t-lang/topic/calling%20methods%20on%20generic%20const%20fn%20rfc%232632/near/209276104" class="zl"><img src="https://rust-lang.github.io/zulip_archive/assets/img/zulip.svg" alt="view this post on Zulip" style="width:20px;height:20px;"></a> RalfJ <a href="https://rust-lang.github.io/zulip_archive/stream/213817-t-lang/topic/calling.20methods.20on.20generic.20const.20fn.20rfc.232632.html#209276104">(Sep 07 2020 at 09:40)</a>:</h4>
<p>when a <code>const fn foo&lt;T: const Trait&gt;(x: T)</code> is called in a runtime <code>fn</code>, does the <code>impl Trait for T</code> need to be <code>const</code>?</p>



<hr><p>Last updated: Aug 07 2021 at 22:04 UTC</p>
</html>